<!--
 * @Author: your name
 * @Date: 2020-12-20 10:24:14
 * @LastEditTime: 2021-12-29 19:48:21
 * @LastEditors: Please set LastEditors
 * @Description: 销售出库详情，该页面能点击审核和记账
 * @FilePath: \cang-chu-guan-li-xi-tong\src\views\chukuguanli\XiaoShouChuKuDetail.vue
-->
<template>
  <a-card>
    <p style="font-size: 18px; text-align: center">生产材料出库单</p>
    <br />
    <a-form-model :model="Form" v-bind="layout"
      ><!-- 顶部的信息  -->
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据号">
            <div>{{ Form.document }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据日期">
            <div>{{ Form.document_date }}</div>
          </a-form-model-item>
        </a-col>
        <!-- ===================新增开始================ -->

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="仓库名称">
            <div>{{ Form.storname }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="产成品仓库">
            <div>{{ Form.finishedProductDepot_dictText }}</div>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="收发类别">
            <div>{{ Form.sendReceiveType_dictText }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="库存组织">
            <div>{{ Form.pkCalbody_dictText }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="领料员">
            <div>{{ Form.picker_dictText }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="公司">
            <div>{{ Form.pkCorp_dictText }}</div>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="产成品分类">
            <div>{{ Form.finishedProductType_dictText }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="农户">
            <div>{{ Form.farmer_dictText }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="所属分厂">
            <div>{{ Form.ownedBranch }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="部门">
            <div>{{ Form.deptId_dictText }}</div>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row> </a-row>
    </a-form-model>

    <a-table
      :columns="columns"
      :data-source="DataSource"
      style="margin-top: 10px"
      :pagination="false"
      :scroll="autoSize"
    >
    </a-table>

    <div style="margin-top: 20px">
      <!-- 单据 -->
      <a-form-model :model="Form" v-bind="layout"
        ><!-- 顶部的信息 -->
        <a-row>
          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="库管员">
              <div>{{ Form.cwhsmanagerid_dictText }}</div>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="负责人">
              <div>{{ Form.responsiblePerson }}</div>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核人">
              <div>{{ Form.inspector }}</div>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核日期">
              <div>{{ Form.balance }}</div>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="制单人">
              <div>{{ Form.singleProducer }}</div>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <!-- 提交按钮组  
      1. 能审核提交的人是不能点击保存的
      2. 能保存的人是不能审核和提交的
      -->
      <div style="margin-top: 20px">
        <center>
          <a-button type="primary" style="margin-right: 20px" @click="goPrint">
            打印
          </a-button>

          <a-button style="margin-right: 20px" disabled> 保存 </a-button>

          <a-button
            @click="Examine"
            style="margin-right: 20px"
            :disabled="!alreadyCheckTag"
          >
            审核
          </a-button>
          <a-button
            @click="antiExamine"
            style="margin-right: 20px"
            :disabled="isAntiExamine"
          >
            反审核
          </a-button>
          <a-button type="primary" @click="save_u8c" style="margin-right: 20px">
            同步至用友
          </a-button>
        </center>
      </div>
    </div>

    <div style="display: none">
      <div id="printCons" style="width: 85%; margin: 0 auto; color: black">
        <!-- // 标题 -->
        <div
          id="style1"
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 30px;
          "
        >
          <div style="margin-left: 10px">
            <div>单据号: {{ Form.document }}</div>
          </div>

          <div style="margin-left: 10px">
            <div>单据日期: {{ Form.document_date }}</div>
          </div>

          <div style="margin-left: 10px">
            <div>收发类别: {{ Form.sendReceiveType_dictText }}</div>
          </div>
        </div>
        <div
          id="style1"
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 30px;
          "
        >
          <div style="margin-left: 10px">
            <div>仓库: {{ Form.storname }}</div>
          </div>
          <div style="margin-left: 60px">
            <div>所属分厂: {{ Form.ownedBranch }}</div>
          </div>
        </div>
        <div
          id="style1"
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 30px;
          "
        >
          <div style="margin-left: 10px">
            <div>部门:{{ Form.deptId_dictText }}</div>
          </div>
          <div style="margin-left: 10px">
            <div>领料员: {{ Form.singleProducer_dictText }}</div>
          </div>
          <div style="margin-left: 10px">
            <div>农户: {{ Form.farmer_dictText }}</div>
          </div>
        </div>
        <div
          id="style1"
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 30px;
          "
        >
          <div style="margin-left: 10px">
            <div>备注:</div>
          </div>
        </div>
        <!-- 表格 -->
        <div class="print-table" style="margin-top: 0px">
          <table
            style="width: 100%; text-align: center; border-collapse: collapse"
            border="0"
            cellspacing="0"
            cellpadding="0"
          >
            <tr>
              <th>存货名称</th>
              <th>单位</th>
              <th>规格</th>
              <th>实发数量</th>
              <th>单价</th>
              <th>金额</th>
              <th>备注</th>
            </tr>
            <tr v-for="(item, index) in printDataSource" :key="index">
              <th>{{ item.inventoryName }}</th>
              <th>{{ item.unit }}</th>
              <th>{{ item.standardModel }}</th>
              <th>{{ item.quantity }}</th>
              <th>{{ item.unitPrice }}</th>
              <th>{{ item.money }}</th>
              <th>{{ item.remark }}</th>
            </tr>
          </table>
        </div>

        <!-- 尾部信息 -->
        <div
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 30px;
          "
        >
          <div style="margin-left: 10px">
            制单人： {{ Form.singleProducer }}
          </div>
          <div style="margin-left: 80px">审核人： {{ Form.inspector }}</div>
        </div>
      </div>
    </div>
  </a-card>
</template>

<script>
import axios from "axios";
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口
import moment from "moment";

import printJS from "print-js";

let columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
  },
  // {
  //   title: "所属单位",
  //   dataIndex: "storageUnit",
  //   key: "storageUnit",
  //   align: "center",
  // },
  {
    title: "仓库编码",
    dataIndex: "depotNo",
    key: "depotNo",
    align: "center",
  },
  {
    title: "仓库名称",
    dataIndex: "depotName",
    key: "depotName",
    align: "center",
  },

  {
    title: "仓位",
    dataIndex: "position_dictText",
    key: "position_dictText",
    align: "center",
  },
  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    key: "inventoryNo",
    align: "center",
  },
  {
    title: "存货名称",
    dataIndex: "inventoryName",
    key: "inventoryName",
    align: "center",
  },
  {
    title: "规格型号",
    dataIndex: "standardModel",
    key: "standardModel",
    align: "center",
  },
  {
    title: "单位",
    key: "unit",
    dataIndex: "unit",
    align: "center",
  },
  {
    title: "数量",
    key: "quantity",
    dataIndex: "quantity",
    align: "center",
  },
  {
    title: "单价",
    key: "unitPrice",
    dataIndex: "unitPrice",
    align: "center",
  },
  {
    title: "金额",
    key: "money",
    dataIndex: "money",
    align: "center",
  },
  {
    title: "源单单号",
    key: "sourceNumber",
    dataIndex: "sourceNumber",
    align: "center",
  },
  {
    title: "批次号",
    key: "batchNumber",
    dataIndex: "batchNumber",
    align: "center",
  },
  // {
  //   title: "产成品分类",
  //   key: "finishedProductType",
  //   dataIndex: "finishedProductType",
  //   align: "center",
  // },
  {
    title: "出库日期",
    key: "deliveryDate",
    dataIndex: "deliveryDate",
    align: "center",
  },
  {
    title: "出菇领料金额",
    key: "amountOfFruitPicking",
    dataIndex: "amountOfFruitPicking",
    align: "center",
    scopedSlots: { customRender: "amountOfFruitPicking" },
  },
  {
    title: "货架",
    dataIndex: "goodsShelves",
    key: "goodsShelves",
    align: "center",
  },
  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
  },
];
export default {
  data() {
    return {
      aa: [],
      u8c_array: [], //u8c传递数据表格的数据源
      arr: [], //
      GeneralBillVO: [], //需给用友传递的data
      ayyany: [],
      ayyanyany: [],
      updateSucessRecordTag: false, //同步至u8c按钮的状态

      Form: {
        id: "", // id
        document: "", // 单据号
        document_date: "", // 单据日期
        deptId: "", // 部门id
        deptId_dictText: "", //部门
        depotName: "", // 仓库名称
        depotNo: "", // 仓库编号
        depotId: "", // 仓库Id
        storageUnit: "", // 所属单位名称
        storageUnitId: "", // 所属单位Id
        storageUnitNo: "", // 所属单位编号

        finishProductInventory: "", //产成品仓库
        finishProductInventoryNo: "", //产成品仓库编码
        finishProductInventoryId: "", //产成品仓库ID
        supplier: "", //供应商
        supplierId: "", //供应商Id

        sendReceiveType: "", // 收发类别名称
        sendReceiveTypeId: "", // 收发类别Id
        responsiblePerson: "", // 负责人名称
        responsiblePersonId: "", // 负责人Id
        inspector: "", // 审核人名称
        inspectorId: "", // 审核人Id
        balance: "", // 审核日期
        singleProducer: "", // 制单人名称
        singleProducerId: "", // 制单人Id

        isSynchronized: "", //是否同步
        isAntiAudit: "", //是否反审核
        isAntiExamine: false, //是否可用反审核
      },
      printDataSource: [],
      // 格式
      layout: {
        labelCol: { span: 8 },
        wrapperCol: { span: 15 },
      },
      printLayout: { labelCol: { span: 5 }, wrapperCol: { span: 19 } },

      columns,
      DataSource: [],
      autoSize: {
        x: 3500,
        y: 670,
      },
      alreadyCheckTag: true, // 可以审核
      alreadyRecordTag: true, // 可以记账
    };
  },
  watch: {
    $route(to, from) {
      //监听路由是否变化
      console.log("to", to);
      let id = to.query.Id;
      console.log("from", from);
      console.log("this.$route.params.articleId", this.$route.params.articleId);
      this.setInitInfo(id);
    },
  },
  mounted() {
    this.getRouterParam();
  },

  methods: {
    getPrint() {
      this.printDataSource = [];
      let sum = 0;
      for (let i = 0; i < this.DataSource.length; i++) {
        let data = {
          inventoryName: this.DataSource[i].inventoryName,
          unit: this.DataSource[i].unit,
          standardModel: this.DataSource[i].standardModel,
          quantity: this.DataSource[i].quantity,
          unitPrice: this.DataSource[i].unitPrice,
          money: this.DataSource[i].money,
          remark: this.DataSource[i].remark,
        };
        sum = sum + this.DataSource[i].quantity;
        this.printDataSource.push(data);
      }

      // 计算合计
      let endData = {
        inventoryName: "合计",
        unit: "",
        standardModel: "",
        quantity: sum,
        unitPrice: "",
        money: "",
      };
      this.printDataSource.push(endData);
    },

    // 打印功能实现
    goPrint() {
      const style = "@page {margin:0 10mm}; "; // 去掉页眉和页脚
      printJS({
        style, // 添加去掉页眉页脚样式
        targetStyles: ["*"],
        type: "html", // 类型
        printable: "printCons", // 表格内容
        maxWidth: 1000,
        // 表头
        header: `
        <h3  style="
            padding-top:10px;
            text-align: center;
            height: 40px;
            line-height: 40px;
            font-size: 20px;
          ">生产材料出库单</h3>
       `,
        // 表格属性及内容
        // properties: [
        //   { field: "inventoryNo", displayName: "存货编码", columnSize: `10%` },
        //   {
        //     field: "inventoryName",
        //     displayName: "存货名称",
        //     columnSize: `30%`,
        //   },
        //   { field: "standardModel", displayName: "规格", columnSize: `20%` },
        //   { field: "unit", displayName: "单位", columnSize: `10%` },
        //   { field: "quantity", displayName: "数量", columnSize: `10%` },
        //   { field: "remark", displayName: "备注", columnSize: `20%` },
        // ],
        // gridHeaderStyle: "border: 1px solid #000;text-align:center", // 表头公用样式
        // gridStyle: "border: 1px solid #000;text-align:center;height:20px", // 表格公用样式
        // 默认字体置中,高度20
      });
    },

    // 审核函数
    Examine() {
      // this.Form.balance = moment().format("YYYY-MM-DD");
      console.log(this.Form.balance);
      let data = {
        id: this.Form.id,
        auditMark: 1,
        balance: this.Form.balance,
        isAntiAudit: "未反审核",
      };

      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("审核成功");
          this.alreadyCheckTag = false;
          this.$router.push("/ProductionMaterialsOutputList");
        } else {
          this.$message.success("审核失败");
        }
      });
    },

    // 提交
    Submit() {
      let data = {
        id: this.Form.id,
        bookkeepingMark: 1,
      };
      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("记账成功");
          this.alreadyRecordTag = false;
        } else {
          this.$message.success("记账失败");
        }
      });
    },
    //! 第一步 同步至用友成功以后调用我们的接口修改同步字段为“已/未同步”
    //是否同步标志位
    postSynchronized(isSynchronized) {
      let data = {
        id: this.Form.id,
        isSynchronized: isSynchronized,
      };
      console.log(data, "11111111111");
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res, 11111111111111111111);
      });
    },
    //是否反审核标志位
    update_audit(isAntiAudit) {
      let data = {
        id: this.Form.id,
        isAntiAudit: isAntiAudit,
      };
      console.log(data, "2222222222222");
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res, 2222222222222);
      });
    },
    //审核标志位
    update_Mark(isOrNo) {
      let data = {
        id: this.Form.id,
        auditMark: isOrNo,
        balance: "",
      };
      this.Form.balance = "";
      console.log(data, "33333333333333333");
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res, 33333333333333);
      });
    },

    // 反审核函数
    async antiExamine() {
      if (this.Form.isSynchronized == "未同步") {
        this.$message.success("未同步至用友，即将进行我方数据库反审核功能");
        //未同步至用友 直接进行反审核
        this.postSynchronized("未同步");
        this.update_audit("已反审核");
        this.update_Mark(2);
        // 跳转回列表页面
        this.$router.push("/ProductionMaterialsOutputList");
      } else {
        if (this.Form.isSynchronized == "已同步") {
          this.$message.success("已同步至用友，调用友接口");
          // fbillflag 单据状态 1删除 2自由(缺省) 3库房签字 4存货系统审核
          let _data = await this.shengChanLingLiaoInSign();
          console.log("_data", _data);
          // 使用 JSON.parse() 方法将数据转换为 JavaScript 对象。
          let flag = JSON.parse(_data.data).datas[0].parentvo.fbillflag;
          //查询后获取操作员，删除用
          this.savecoperator = JSON.parse(
            _data.data
          ).datas[0].parentvo.coperatorid_code;
          console.log("查询后获取操作员，删除用", this.savecoperator);

          if (_data.status == "success") {
            if (flag == "4") {
              this.$message.error("已签字，不允许反审核！");
            } else if (flag == "3") {
              // 查询成功后进行生产材料的取消签字接口
              let _unsignFlag = await this.shengChanLingLiaoUnsign();
              console.log("_unsignFlag", _unsignFlag);
              if (_unsignFlag == "success") {
                console.log("生产材料退库单取消签字成功");
                //!我方反审核 todo
                this.postSynchronized("未同步");

                this.update_audit("已反审核");
                this.update_Mark(2);

                // 跳转回列表页面
                this.$router.push("/productionMaterialOutCancelList");
              }
            } else {
              // 查询成功后进行生产材料的取消签字接口
              let _deleteFlag = await this.shengChanLingLiaoDelete();
              console.log("_deleteFlag", _deleteFlag);
              if (_deleteFlag == "success") {
                console.log("生产材料退库单删除成功");
                //!我方反审核 todo
                this.postSynchronized("未同步");
                this.update_audit("已反审核");
                this.update_Mark(2);

                // 跳转回列表页面
                this.$router.push("/ProductionMaterialsOutputList");
              }
            }
          }
        }
      }
    },

    // !生产领料单查询
    shengChanLingLiaoInSign() {
      // u8c接口
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/api/u8cloud/api/ic/materialout/query",
          data: {
            billcode: this.Form.document, //!单据号 因为用友暂时没有保存上我们的单据号，先用他们的单据号测试
            // billcode: this.Form.vbillcode, //单据号

            corp: "1001", //公司
            date_begin: this.Form.document_date, //起始日期
            date_end: this.Form.document_date, //结束日期
            inventory: "", //存货
            page_now: "1", //起始页
            // warehouse: this.Form.storname, //仓库
          },
        }).then((response) => {
          resolve(response.data);
          console.log("返回的数据为::::", response.data);
          let _data = JSON.parse(response.data.data);
          console.log(_data, 7777777777777);
          if (response.data.status == "success") {
            this.$message.success("查询成功");
          } else {
            this.$message.error(response.data.errormsg);
          }
        });
      });
    },

    //! 调用用友生产材料单取消签字接口
    shengChanLingLiaoUnsign() {
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/api/u8cloud/api/ic/materialout/unsign",
          data: {
            queryInfo: {
              // vbillcode: this.Form.document,
              billcode: this.Form.document, //!单据号 因为用友暂时没有保存上我们的单据号，先用他们的单据号测试
              // billcode: this.Form.vbillcode, //单据号
              date_begin: this.Form.document_date,
              date_end: this.Form.document_date,
              corp: "1001",
            },
            unsignInfo: {
              coperator: this.savecoperator,
            },
          },
        }).then((response) => {
          resolve(response.data.status);
          if (response.data.status == "success") {
            this.shengChanLingLiaoDelete();
            // this.$message.success("用友删除成功");
          } else {
            this.$message.error(response.data.errormsg);
          }
        });
      });
    },
    //! 调用用友生产材料单删除接口
    shengChanLingLiaoDelete() {
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/api/u8cloud/api/ic/materialout/delete",
          data: {
            queryInfo: {
              // vbillcode: this.Form.document,
              billcode: this.Form.document, //!单据号 因为用友暂时没有保存上我们的单据号，先用他们的单据号测试
              // billcode: this.Form.vbillcode, //单据号
              date_begin: this.Form.document_date,
              date_end: this.Form.document_date,
              corp: "1001",
            },
            deleteInfo: {
              coperator: this.savecoperator,
            },
          },
        }).then((response) => {
          resolve(response.data.status);
          if (response.data.status == "success") {
            this.$message.success("用友删除成功");
          } else {
            this.$message.error(response.data.errormsg);
          }
        });
      });
    },

    // 点击提交按钮，将产成品入库单传递给用友
    save_u8c() {
      this.ayyanyany = [];
      if (this.aa[0].auditMark_dictText == "已审核") {
        for (let i = 0; i < this.aa.length; i++) {
          console.log("i", i);
          this.arr = [];
          console.log("this.aa[i].length", this.aa[i].length);
          let data = {
            pk_corp: "1001", //公司编码
            cinventoryid: this.aa[i].invcode, //存货ID √
            noutnum: this.aa[i].quantity, //实出数量 √
            // vsourcebillcode: this.u8c_array[i][j].document, //单据号 √
            vnotebody: this.aa[i].remark, // 行备注 √
            dbizdate: moment(this.aa[i].deliveryDate).format("YYYY-MM-DD"), //出库日期（业务日期）√
            pk_defdoc4: this.aa[i].amountOfFruitPicking, //出菇领料金额
          };
          this.arr.push(data);
          console.log("this.arr", this.arr);
        }
        this.ayyany = {
          parentvo: {
            cdispatcherid: this.aa[0].sendReceiveType1_dictText, //收发类别名称 √
            coperatorid: this.aa[0].singleProducerByCode_dictText, //制单人  √
            cbizid: this.aa[0].workNO, //业务员ID（领料员） √
            cwhsmanagerid: this.aa[0].cwhsmanagerid1_dictText, //库管员ID  √
            cdptid: this.aa[0].cdptidByCode_dictText, //部门 √
            cwarehouseid: this.aa[0].storcode, //仓库id  √
            dbilldate: moment(this.aa[0].documentDate).format("YYYY-MM-DD"), //单据日期
            pk_calbody: "100001", //库存组织PK=仓库编号
            pk_corp: "1001", //公司
            // vreceiptcode: this.u8c_array[i][0].document, //单据号 √
            vbillcode: this.aa[0].document, //!单据号 √
            vuserdef5: this.aa[0].finishedProductType1_dictText, // 自定义项5-产成品分类 √
            vuserdef6: this.aa[0].finishedProductDepot1_dictText, // 自定义项6-产成品仓库 √
            vuserdef3: this.aa[0].farmer1_dictText, //自定义项3-农户 √
            vnote: "", //备注 √
          },
          childrenvo: this.arr,
        };

        this.ayyanyany.push(this.ayyany);
        console.log("this.GeneralBillVO::::", this.ayyanyany);
        // u8c接口
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/api/u8cloud/api/ic/materialout/save/sign",
          data: {
            GeneralBillVO: this.ayyanyany,
          },
        }).then((response) => {
          console.log("response====>", response);
          console.log(response.data.status, 666666666666666666);
          // let _data = JSON.parse(response.data.data);
          // console.log(_data, 7777777777777);

          if (response.data.status == "success") {
            this.$message.success("同步成功");
            this.updateSucessRecordTag = true;
            this.Form.isSynchronized = "已同步";

            this.postSynchronized("已同步");
            // this.Form.vbillcode = _data[0].parentvo.vbillcode;
            console.log("this.Form.vbillcode", this.Form.vbillcode);
            // this.savecoperator = _data[0].parentvo.coperatorid_code;
            console.log("this.Form.savecoperator", this.savecoperator);
            // 跳转回列表页面
            this.$router.push("/ProductionMaterialsOutputList");
            // this.$router.push("/ProductionMaterialsOutputList");
            // alert("同步成功！");
          } else {
            
            console.log("response.data.errormsg",response.data.errormsg);
            this.$message.error(response.data.errormsg);
          }
          // let _data = JSON.parse(response.data.data);
          // this.Form.vbillcode = _data[0].parentvo.vbillcode;
          // this.savecoperator = _data[0].parentvo.coperatorid_code;
        });
      } else {
        this.$message.error("请先审核，再进行同步!");
      }
    },
    // 获取路由跳转参数
    getRouterParam() {
      console.log("查询参数:::", this.$route.query.Id);

      // 通过出入库id 查询出入库信息
      if (typeof this.$route.query.Id == "undefined") {
        console.log("常规跳转");
      } else {
        this.setInitInfo(this.$route.query.Id);
      }
    },

    // 路由跳转,设置初始化信息
    setInitInfo(id) {
      this.isAntiExamine = false;
      comHttp
        .getInOrOutStorageOrderAndGoodsInfoById("?id=" + id)
        .then((res) => {
          console.log("通过Id查询出来的信息::::", res);
          // 是否审核
          if (res.result.list[0].auditMark == 1) {
            this.alreadyCheckTag = false;
          } else {
            this.alreadyCheckTag = true;
          }

          // 是否记账
          if (res.result.list[0].bookkeepingMark == 1) {
            this.alreadyRecordTag = false;
          } else {
            this.alreadyRecordTag = true;
          }

          this.otherId = res.result.list[0].otherId; // 表一 Id
          this.Form = {
            pkCalbody_dictText: res.result.list[0].pkCalbody_dictText, // 库存组织

            isSynchronized: res.result.list[0].isSynchronized, //是否同步
            isAntiAudit: res.result.list[0].isAntiAudit, //是否反审核
            auditMark: res.result.list[0].auditMark, //是否审核数字
            auditMark_dictText: res.result.list[0].auditMark_dictText, //是否审核名字

            id: res.result.list[0].otherId, // 表一 Id
            deptId_dictText: res.result.list[0].deptId_dictText, // 部门
            document: res.result.list[0].document, // 单据号
            document_date: res.result.list[0].documentDate, // 单据日期
            supplier_dictText: res.result.list[0].supplier_dictText, // 供应商
            finishedProductDepot_dictText:
              res.result.list[0].finishedProductDepot_dictText, // 产成品仓库
            sendReceiveType_dictText:
              res.result.list[0].sendReceiveType_dictText, // 收发类别
            responsiblePerson: res.result.list[0].responsiblePerson_dictText, // 负责人
            inspector: res.result.list[0].inspector_dictText, // 审核人
            singleProducer: res.result.list[0].singleProducer_dictText, // 制单人
            balance: res.result.list[0].balance,
            storageUnit_dictText: res.result.list[0].storageUnit_dictText,
            storname: res.result.list[0].storname,
            singleProducer_dictText: res.result.list[0].singleProducer_dictText,
            pkCorp_dictText: res.result.list[0].pkCorp_dictText,
            invclassname: res.result.list[0].invclassname,
            farmer_dictText: res.result.list[0].farmer_dictText,
            ownedBranch: res.result.list[0].ownedBranch_dictText,
            finishedProductType_dictText:
              res.result.list[0].finishedProductTypeDictText,
            finishedProductType: res.result.list[0].finishedProductType,
            picker_dictText: res.result.list[0].picker_dictText,
            cwhsmanagerid_dictText: res.result.list[0].cwhsmanagerid_dictText,
          };
          this.DataSource = [];
          for (let i = 0; i < res.result.list.length; i++) {
            let data = {
              key: i + 1,
              id: res.result.list[i].twoId, // 表二Id
              otherId: res.result.list[i].otherId,
              depotNo: res.result.list[i].storcode, // 仓库编码
              depotName: res.result.list[i].storname, // 仓库名称
              position_dictText: res.result.list[i].position_dictText, // 库位
              depotLocation_dictText: res.result.list[i].depotLocation_dictText, // 仓位
              storageUnit: res.result.list[i].storageUnit_dictText, // 所属单位
              inventoryNo: res.result.list[i].inventoryId_dictText, // 存货编码
              inventoryName: res.result.list[i].invname, // 存货名称
              standardModel: res.result.list[i].invspec, // 规格型号
              unit: res.result.list[i].measname, // 单位
              quantity: res.result.list[i].quantity, // 数量
              sourceNumber: res.result.list[i].sourceNumber, // 源单单号
              batchNumber: res.result.list[i].batchNumber, // 源单单号
              deliveryDate: res.result.list[i].deliveryDate, // 出库日期
              remark: res.result.list[i].remarks, // 备注
              // 产成品分类
              amountOfFruitPicking: res.result.list[i].amountOfFruitPicking, // 出菇领料金额
            };
            this.DataSource.push(data);
          }
          this.getPrint();
          console.log("表格信息:::::", this.DataSource);
          this.aa = res.result.list;
          this.sortArr(res.result.list, "depotNo");

          if (
            (this.Form.isAntiAudit == "已反审核" &&
              this.Form.auditMark == "1") ||
            (this.Form.isAntiAudit == "未反审核" &&
              this.Form.auditMark == "2") ||
            this.Form.auditMark == "2"
          ) {
            this.isAntiExamine = true;
          }
        });
    },

    // this.u8c_array数组根据仓库编码筛选，将相同的仓库编码放在一个数组里
    sortArr(arr, str) {
      var newArr = [],
        newArrItem = [],
        // 临时变量
        tempArr = [];
      // 按照特定的参数将数组排序将具有相同值的排在一起
      arr = arr.sort(function (a, b) {
        var s = a[str],
          t = b[str];

        return s < t ? -1 : 1;
      });

      if (arr.length) {
        tempArr = arr[0][str];
      }

      // 将相同类别的对象添加到统一个数组
      for (var i in arr) {
        if (arr[i][str] === tempArr) {
          console.log("tempArr", tempArr);
          newArrItem.push(arr[i]);
        } else {
          tempArr = arr[i][str];
          newArr.push(newArrItem);
          newArrItem = [arr[i]];
        }
      }

      // 将最后的内容推出新数组
      newArr.push(newArrItem);
      this.u8c_array = newArr;
      console.log("u8c_arr", this.u8c_array);
    },
  },
};
</script>

<style>
.print-table table td,
.print-table table th,
.print-table table tr {
  border: 1px solid black;
}
.print-table table tr {
  height: 30px;
}
</style>
